<!--
 * @FileDescription: 生产储存主弹窗左侧Tab
 * @Author: 祝小文
 * @Date: 2022-09-27 16:22
-->

<script setup lang="ts">
import { emitter } from '@/composables'
const chemicalStore = useChemicalStore()

const tabLeftList = ref([
  {
    id: 0,
    menuCode: 'gq',
    text: '罐 区',
    count: 0,
  },
  {
    id: 1,
    menuCode: 'zz',
    text: '装 置',
    count: 0,
  },
  {
    id: 2,
    menuCode: 'ck',
    text: '仓 库',
    count: 0,
  },
  {
    id: 3,
    menuCode: 'dc',
    text: '堆 场',
    count: 0,
  },
  {
    id: 4,
    menuCode: 'hj',
    text: '火 炬',
    count: 0,
  },
])

const activeIndex = ref(0) //当前tab选中项

/** 左侧tab点击事件 通知父组件切换内容 */
const emit = defineEmits(['tabClick'])
const tabClick = (id: number) => {
  activeIndex.value = id
  emit('tabClick', id)
}

/** 加载统计数据 */
const loadMenuTjInfo = () => {
  queryMenuTjInfo({ key: chemicalStore.qyInfo.id }).then((res: any) => {
    tabLeftList.value.forEach((tabItem: any) => {
      res.forEach((item: any) => {
        if (item.menuCode === tabItem.menuCode) {
          tabItem.count = item.tj
        }
      })
    })
  })
}
loadMenuTjInfo()

emitter.on('tabLeft_refreshData', () => {
  loadMenuTjInfo()
})

onUnmounted(() => {
  emitter.off('tabLeft_refreshData')
})
</script>

<template>
  <div class="ps-tableft-container">
    <div
      v-for="item in tabLeftList"
      :key="item.id"
      class="tab-item"
      :class="{ 'active-color': activeIndex === item.id }"
      @click="tabClick(item.id)"
    >
      <span>{{ item.text }}</span>
      <span>{{ item.count }}</span>
    </div>
  </div>
</template>

<style lang="less" scoped>
.ps-tableft-container {
  width: 44px;
  margin-top: 14px;
  .tab-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 140px;
    margin-bottom: 15px;
    border-right: 2px solid #11b3a1;
    background: rgba(1, 10, 15, 0.7);
    transform: skewy(-30deg);
    cursor: pointer;
    span:first-child {
      margin-bottom: 15px;
      font-size: 20px;
      color: #fff;
      writing-mode: vertical-rl;
      transform: skewy(30deg);
    }
    span:last-child {
      font-size: 18px;
      font-weight: 700;
      color: #00ff66;
      transform: skewy(30deg);
    }
  }
  .active-color {
    background-color: rgba(26, 137, 145, 0.8);
    span:first-child {
      font-weight: 700;
    }
  }
}
</style>
